package com.example.order.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.order.service.OrderService;
import com.example.params.OrderParams;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 刘武贵
 * @Date 2024/2/28 1:08
 * @Description 功能描述：订单控制器
 * Nacos安装 和 集群搭建_nacos1.4.3安装包-CSDN博客 https://blog.csdn.net/qq_46371399/article/details/128378358
 */
@Slf4j
@RestController
public class OrderController {

    /**
     * 订单业务接口
     */
    @Autowired
    @Qualifier(value = "orderServiceV8")
    private OrderService orderService;

    /**
     * 提交订单
     * @param orderParams 订单参数
     * @return 提交结果
     */
   @PostMapping(value = "/submit_order")
    public String submitOrder(@RequestBody OrderParams orderParams){
        log.info("提交订单时传递的参数:{}", JSONObject.toJSONString(orderParams));
        orderService.saveOrder(orderParams);
        return "success";
    }

    /**
     * 处理并发请求
     * @return 返回字符串binghe
     */
    @GetMapping(value = "/concurrent_request")
    public String concurrentRequest(){
        log.info("测试业务在高并发场景下是否存在问题");
        return "binghe";
    }

    /**
     * 测试Sentinel（演示Sentinel的直接流控模式）
     * @return 返回sentinel
     */
    @GetMapping(value = "/test_sentinel")
    public String testSentinel(){
        log.info("测试Sentinel");
        return "sentinel";
    }

    /**
     * 测试Sentinel2（演示Sentinel的关联流控模式）
     * @return 返回sentinel2
     */
    @GetMapping(value = "/test_sentinel2")
    public String testSentinel2(){
        log.info("测试Sentinel2");
        return "sentinel2";
    }
}